package main

import (
	"fmt"
	"golang.org/x/net/context"
	"k8s-client/modules/namespace"
	"k8s-client/modules/node"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/clientcmd"
)

func main() {

	restclient_config, err := clientcmd.BuildConfigFromFlags("", "./conf/admin.conf")
	if err != nil {
		fmt.Println("fail to read config file", err)
	}
	config, err := kubernetes.NewForConfig(restclient_config)
	if err != nil {
		fmt.Println("fail to build config", err)
	}
	nodeList, err := config.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{})
	v1_nodes := node.Show(nodeList)

	namespaceList, err := config.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{})
	if err != nil {
		fmt.Println("fail to get namespace list", err)
	}

	list := namespace.NamespaceList(namespaceList)

	node.Get_pods_by_node(config.CoreV1(), list, v1_nodes)

}
